<?php

namespace App\depository;

use App\Enum\RolesEnum;
use App\Models\SubRolesModel;

class SubRolesDep
{
    public $model;

    public function __construct()
    {
        $this->model = new SubRolesModel();
    }

    public function add($data)
    {
        $res = $this->model->insert($data);
        return $res;
    }

    public function addGetId($data){
        $res = $this->model->insertGetId($data);
        return $res;
    }

    public function upd($id, $data)
    {
        $res = $this->model->where('id', $id)->update($data);
        return $res;
    }

    public function del($id)
    {
        $res = $this->model->where('id', $id)->delete();
        return $res;
    }

    public function list($teamId)
    {
        $res = $this->model
            ->where('team_id',$teamId)
            ->get();

        return $res;
    }

    public function allOk($teamId){
        $res = $this->model->where('team_id',$teamId)->where('status',RolesEnum::STATUS_YES)->get();
        return $res;
    }

    public function firstByGuardName($guardName)
    {
        $res = $this->model->where('guard_name', $guardName)->first();
        return $res;
    }

    public function firstByRoleId($roleId){
        $res = $this->model->where('id',$roleId)->first();
        return $res;
    }
}
